import java.util.Map;
import java.util.Random;

public class equation {
    private int first = 1;
    private int operator = 0;
    private int second = 1;

    private int result;

    public int getResult() {
        return result;
    }

    public void setResult(int result) {
        this.result = result;
    }

    public int getFirst() {
        return first;
    }

    public void setFirst(int first) {
        this.first = first;
    }

    public int getOperator() {
        return operator;
    }

    public equation() {
    }

    public void setOperator(int operator) {
        this.operator = operator;
    }

    public equation(int first, int operator, int second) {
        this.first = first;
        this.operator = operator;
        this.second = second;
    }

    public int getSecond() {
        return second;
    }

    public void setSecond(int second) {
        this.second = second;
    }
    void operation(equation[] equation){
        //方法operation用于运算
        //直接传递对象数组进去
        //把结果放在result属性里
        for(int i=0;i<50 ;i++ ){
            if(equation[i].getOperator() == 0){
                //0是加法
                equation[i].setResult(equation[i].getFirst() + equation[i].getSecond() );
            }
            else {
                //1是减法
                equation[i].setResult(equation[i].getFirst() - equation[i].getSecond() );
            }
        }
    }
    void newEquation(equation[] equations){
        //赋值方法
        for (int i = 0;i < 50 ; i++) {
            Random random = new Random();
            int a,b,c;
            a = random.nextInt(101);
            b = random.nextInt(2);
            c = random.nextInt(101);
            equations[i].setFirst(a);
            equations[i].setOperator(b);
            equations[i].setSecond(c);
        }
    }
    void printEquation(equation[] equations){
        //打印方法
        for (int i=0 ; i < 50 ; i++){
            char o;
            if(equations[i].getOperator() == 0) o = '+';
            else o = '-';
            if(o == '-' && equations[i].getFirst() < equations[i].getSecond()){
                System.out.println( "第" + (i+1) + "个算式：" +
                        equations[i].getSecond() +
                        o + equations[i].getFirst());
            }
            else {
                System.out.println( "第" + (i+1) + "个算式：" +
                        equations[i].getFirst() +
                        o + equations[i].getSecond());
            }
        }

    }
    void printResult(equation[] equations){
        for(int i = 0 ; i < 50 ; i ++ ){
            System.out.println("第" + (i+1) + "个算式的答案是：" + Math.abs(equations[i].getResult()) );
        }

    }
}
